{
 "cells": [
  {
   "attachments": {},
   "cell_type": "markdown",
   "id": "390b7218",
   "metadata": {},
   "source": [
    "# ECG ID DATASET"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "68739b90-cbbb-4003-9910-5365e2cd144e",
   "metadata": {},
   "source": [
    "## Importing the Libraries"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "50ae009b",
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import numpy as np\n",
    "import seaborn as sns\n",
    "import matplotlib.pyplot as plt\n",
    "%matplotlib inline\n",
    "from sklearn.model_selection import train_test_split\n",
    "from sklearn.metrics import accuracy_score, confusion_matrix, precision_score, f1_score, recall_score, classification_report \n",
    "from sklearn.svm import SVC\n",
    "import warnings"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "f15c9bbc",
   "metadata": {},
   "outputs": [],
   "source": [
    "warnings.simplefilter('ignore')"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d7589180-8238-47a8-bef0-4455cc11ddf8",
   "metadata": {},
   "source": [
    "## Reading the data and processing it"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "4f6d12e6",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>ID</th>\n",
       "      <th>CC_1</th>\n",
       "      <th>CC_2</th>\n",
       "      <th>CC_3</th>\n",
       "      <th>CC_4</th>\n",
       "      <th>CC_5</th>\n",
       "      <th>CC_6</th>\n",
       "      <th>CC_7</th>\n",
       "      <th>CC_8</th>\n",
       "      <th>CC_9</th>\n",
       "      <th>CC_10</th>\n",
       "      <th>CC_11</th>\n",
       "      <th>CC_12</th>\n",
       "      <th>ENTROPY</th>\n",
       "      <th>ZCR</th>\n",
       "      <th>PERSON</th>\n",
       "      <th>TARGET</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>Person_58_rec_1_0</td>\n",
       "      <td>-5.615605</td>\n",
       "      <td>1.950304</td>\n",
       "      <td>1.219107</td>\n",
       "      <td>0.604346</td>\n",
       "      <td>0.132980</td>\n",
       "      <td>-0.124852</td>\n",
       "      <td>-0.173601</td>\n",
       "      <td>-0.089909</td>\n",
       "      <td>0.023068</td>\n",
       "      <td>0.087169</td>\n",
       "      <td>0.077531</td>\n",
       "      <td>0.017479</td>\n",
       "      <td>-1.144802</td>\n",
       "      <td>27.0</td>\n",
       "      <td>58</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>Person_58_rec_1_1</td>\n",
       "      <td>-4.553929</td>\n",
       "      <td>1.534944</td>\n",
       "      <td>1.020583</td>\n",
       "      <td>0.582540</td>\n",
       "      <td>0.206446</td>\n",
       "      <td>-0.043117</td>\n",
       "      <td>-0.138676</td>\n",
       "      <td>-0.108155</td>\n",
       "      <td>-0.017692</td>\n",
       "      <td>0.061794</td>\n",
       "      <td>0.085258</td>\n",
       "      <td>0.047250</td>\n",
       "      <td>-1.204611</td>\n",
       "      <td>23.0</td>\n",
       "      <td>58</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>Person_58_rec_1_2</td>\n",
       "      <td>-4.547791</td>\n",
       "      <td>1.579749</td>\n",
       "      <td>1.006604</td>\n",
       "      <td>0.557267</td>\n",
       "      <td>0.198428</td>\n",
       "      <td>-0.030084</td>\n",
       "      <td>-0.117707</td>\n",
       "      <td>-0.094800</td>\n",
       "      <td>-0.018126</td>\n",
       "      <td>0.053624</td>\n",
       "      <td>0.081432</td>\n",
       "      <td>0.056048</td>\n",
       "      <td>-1.244808</td>\n",
       "      <td>25.0</td>\n",
       "      <td>58</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>Person_58_rec_1_3</td>\n",
       "      <td>-4.268481</td>\n",
       "      <td>1.416923</td>\n",
       "      <td>0.925869</td>\n",
       "      <td>0.540707</td>\n",
       "      <td>0.217304</td>\n",
       "      <td>-0.004639</td>\n",
       "      <td>-0.105239</td>\n",
       "      <td>-0.101285</td>\n",
       "      <td>-0.038169</td>\n",
       "      <td>0.030327</td>\n",
       "      <td>0.063515</td>\n",
       "      <td>0.047249</td>\n",
       "      <td>-1.234096</td>\n",
       "      <td>33.0</td>\n",
       "      <td>58</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>Person_58_rec_1_4</td>\n",
       "      <td>-5.005483</td>\n",
       "      <td>1.668945</td>\n",
       "      <td>1.127145</td>\n",
       "      <td>0.622664</td>\n",
       "      <td>0.191501</td>\n",
       "      <td>-0.070517</td>\n",
       "      <td>-0.140332</td>\n",
       "      <td>-0.076495</td>\n",
       "      <td>0.023819</td>\n",
       "      <td>0.080875</td>\n",
       "      <td>0.067233</td>\n",
       "      <td>0.006223</td>\n",
       "      <td>-1.188146</td>\n",
       "      <td>25.0</td>\n",
       "      <td>58</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7612</th>\n",
       "      <td>Person_09_rec_2_14</td>\n",
       "      <td>-5.409978</td>\n",
       "      <td>1.501586</td>\n",
       "      <td>1.030578</td>\n",
       "      <td>0.648997</td>\n",
       "      <td>0.304388</td>\n",
       "      <td>0.034882</td>\n",
       "      <td>-0.129555</td>\n",
       "      <td>-0.185276</td>\n",
       "      <td>-0.154627</td>\n",
       "      <td>-0.076417</td>\n",
       "      <td>0.007416</td>\n",
       "      <td>0.064132</td>\n",
       "      <td>-1.485764</td>\n",
       "      <td>31.0</td>\n",
       "      <td>9</td>\n",
       "      <td>90</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7613</th>\n",
       "      <td>Person_09_rec_2_15</td>\n",
       "      <td>-5.221250</td>\n",
       "      <td>1.422368</td>\n",
       "      <td>0.988907</td>\n",
       "      <td>0.646708</td>\n",
       "      <td>0.329378</td>\n",
       "      <td>0.068954</td>\n",
       "      <td>-0.102432</td>\n",
       "      <td>-0.173630</td>\n",
       "      <td>-0.158413</td>\n",
       "      <td>-0.089536</td>\n",
       "      <td>-0.007052</td>\n",
       "      <td>0.054492</td>\n",
       "      <td>-1.406686</td>\n",
       "      <td>29.0</td>\n",
       "      <td>9</td>\n",
       "      <td>90</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7614</th>\n",
       "      <td>Person_09_rec_2_16</td>\n",
       "      <td>-5.749667</td>\n",
       "      <td>1.599961</td>\n",
       "      <td>1.097240</td>\n",
       "      <td>0.682518</td>\n",
       "      <td>0.304429</td>\n",
       "      <td>0.006678</td>\n",
       "      <td>-0.173801</td>\n",
       "      <td>-0.229035</td>\n",
       "      <td>-0.182450</td>\n",
       "      <td>-0.079458</td>\n",
       "      <td>0.028369</td>\n",
       "      <td>0.099481</td>\n",
       "      <td>-1.367448</td>\n",
       "      <td>31.0</td>\n",
       "      <td>9</td>\n",
       "      <td>90</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7615</th>\n",
       "      <td>Person_09_rec_2_17</td>\n",
       "      <td>-5.256631</td>\n",
       "      <td>1.428802</td>\n",
       "      <td>1.007710</td>\n",
       "      <td>0.670232</td>\n",
       "      <td>0.349533</td>\n",
       "      <td>0.080370</td>\n",
       "      <td>-0.101148</td>\n",
       "      <td>-0.180435</td>\n",
       "      <td>-0.169438</td>\n",
       "      <td>-0.100837</td>\n",
       "      <td>-0.015856</td>\n",
       "      <td>0.049308</td>\n",
       "      <td>-1.377399</td>\n",
       "      <td>27.0</td>\n",
       "      <td>9</td>\n",
       "      <td>90</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7616</th>\n",
       "      <td>Person_09_rec_2_18</td>\n",
       "      <td>-4.966675</td>\n",
       "      <td>1.394867</td>\n",
       "      <td>0.969983</td>\n",
       "      <td>0.635738</td>\n",
       "      <td>0.324243</td>\n",
       "      <td>0.067133</td>\n",
       "      <td>-0.102976</td>\n",
       "      <td>-0.173876</td>\n",
       "      <td>-0.158093</td>\n",
       "      <td>-0.087367</td>\n",
       "      <td>-0.001349</td>\n",
       "      <td>0.064970</td>\n",
       "      <td>-1.536645</td>\n",
       "      <td>21.0</td>\n",
       "      <td>9</td>\n",
       "      <td>90</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>13556 rows × 17 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                      ID      CC_1      CC_2      CC_3      CC_4      CC_5  \\\n",
       "0      Person_58_rec_1_0 -5.615605  1.950304  1.219107  0.604346  0.132980   \n",
       "1      Person_58_rec_1_1 -4.553929  1.534944  1.020583  0.582540  0.206446   \n",
       "2      Person_58_rec_1_2 -4.547791  1.579749  1.006604  0.557267  0.198428   \n",
       "3      Person_58_rec_1_3 -4.268481  1.416923  0.925869  0.540707  0.217304   \n",
       "4      Person_58_rec_1_4 -5.005483  1.668945  1.127145  0.622664  0.191501   \n",
       "...                  ...       ...       ...       ...       ...       ...   \n",
       "7612  Person_09_rec_2_14 -5.409978  1.501586  1.030578  0.648997  0.304388   \n",
       "7613  Person_09_rec_2_15 -5.221250  1.422368  0.988907  0.646708  0.329378   \n",
       "7614  Person_09_rec_2_16 -5.749667  1.599961  1.097240  0.682518  0.304429   \n",
       "7615  Person_09_rec_2_17 -5.256631  1.428802  1.007710  0.670232  0.349533   \n",
       "7616  Person_09_rec_2_18 -4.966675  1.394867  0.969983  0.635738  0.324243   \n",
       "\n",
       "          CC_6      CC_7      CC_8      CC_9     CC_10     CC_11     CC_12  \\\n",
       "0    -0.124852 -0.173601 -0.089909  0.023068  0.087169  0.077531  0.017479   \n",
       "1    -0.043117 -0.138676 -0.108155 -0.017692  0.061794  0.085258  0.047250   \n",
       "2    -0.030084 -0.117707 -0.094800 -0.018126  0.053624  0.081432  0.056048   \n",
       "3    -0.004639 -0.105239 -0.101285 -0.038169  0.030327  0.063515  0.047249   \n",
       "4    -0.070517 -0.140332 -0.076495  0.023819  0.080875  0.067233  0.006223   \n",
       "...        ...       ...       ...       ...       ...       ...       ...   \n",
       "7612  0.034882 -0.129555 -0.185276 -0.154627 -0.076417  0.007416  0.064132   \n",
       "7613  0.068954 -0.102432 -0.173630 -0.158413 -0.089536 -0.007052  0.054492   \n",
       "7614  0.006678 -0.173801 -0.229035 -0.182450 -0.079458  0.028369  0.099481   \n",
       "7615  0.080370 -0.101148 -0.180435 -0.169438 -0.100837 -0.015856  0.049308   \n",
       "7616  0.067133 -0.102976 -0.173876 -0.158093 -0.087367 -0.001349  0.064970   \n",
       "\n",
       "       ENTROPY   ZCR  PERSON  TARGET  \n",
       "0    -1.144802  27.0      58       0  \n",
       "1    -1.204611  23.0      58       0  \n",
       "2    -1.244808  25.0      58       0  \n",
       "3    -1.234096  33.0      58       0  \n",
       "4    -1.188146  25.0      58       0  \n",
       "...        ...   ...     ...     ...  \n",
       "7612 -1.485764  31.0       9      90  \n",
       "7613 -1.406686  29.0       9      90  \n",
       "7614 -1.367448  31.0       9      90  \n",
       "7615 -1.377399  27.0       9      90  \n",
       "7616 -1.536645  21.0       9      90  \n",
       "\n",
       "[13556 rows x 17 columns]"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Importing Data file\n",
    "channel_0 = pd.read_csv(r\"n\\Features\\Feature_ECG_ID_Channel_0.csv\")\n",
    "channel_1 = pd.read_csv(r\"\\Features\\Feature_ECG_ID_Channel_1.csv\")\n",
    "dataset = pd.concat([channel_0,channel_1])\n",
    "dataset"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "6e38719a-919a-46f5-bd75-c0be338a3283",
   "metadata": {},
   "outputs": [],
   "source": [
    "features = dataset[[\"CC_1\",\"CC_2\",\"CC_3\",\"CC_4\",\"CC_5\",\"CC_6\",\"CC_7\",\"CC_8\",\"CC_9\",\"CC_10\",\"CC_11\",\"CC_12\",\"ENTROPY\",\"ZCR\"]].to_numpy()\n",
    "\n",
    "labels = dataset[\"TARGET\"]\n",
    "labels = list(labels.to_numpy().reshape(1,len(labels))[0])\n",
    "\n",
    "X_train, X_test, y_train, y_test = train_test_split(features,labels, test_size = 0.3, random_state = 10)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a9960300-36a7-414b-bf3a-25b1c9b4a3d3",
   "metadata": {},
   "source": [
    "## Building a Support Vector Machine (SVM) on train data"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "07281ba9-8fcd-4869-8669-765c40394118",
   "metadata": {},
   "source": [
    "#### (i) SVM using Linear kernel"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "61f2469c",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0.82370297516597\n"
     ]
    }
   ],
   "source": [
    "svc_model = SVC(kernel='linear', C=15000)\n",
    "svc_model.fit(X_train, y_train)\n",
    " \n",
    "prediction = svc_model.predict(X_test)\n",
    "accuracy = accuracy_score(prediction,y_test)\n",
    "print(accuracy)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "9fbe24c9-9606-4e4f-b494-7a802a486187",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "              precision    recall  f1-score   support\n",
      "\n",
      "           0       0.36      0.83      0.50         6\n",
      "           1       0.62      0.67      0.64        12\n",
      "           2       0.92      0.97      0.94        35\n",
      "           3       0.69      0.50      0.58        18\n",
      "           4       0.33      0.23      0.27        13\n",
      "           5       1.00      0.82      0.90        11\n",
      "           6       0.45      0.74      0.56        34\n",
      "           7       0.45      0.45      0.45        11\n",
      "           8       0.64      0.55      0.59        42\n",
      "           9       0.59      0.67      0.62        45\n",
      "          11       0.79      0.61      0.69        38\n",
      "          12       0.51      0.46      0.49        39\n",
      "          13       0.50      0.64      0.56        14\n",
      "          15       0.18      0.18      0.18        11\n",
      "          16       0.47      0.70      0.56        20\n",
      "          17       0.73      0.40      0.52        20\n",
      "          18       0.00      0.00      0.00         7\n",
      "          19       0.53      0.73      0.62        11\n",
      "          20       0.54      0.68      0.60        22\n",
      "          21       0.42      0.41      0.42        39\n",
      "          22       0.74      0.70      0.72        20\n",
      "          23       0.00      0.00      0.00         5\n",
      "          24       0.73      0.84      0.78        19\n",
      "          25       0.26      0.25      0.26        24\n",
      "          26       0.18      0.15      0.17        13\n",
      "          27       0.38      0.23      0.29        22\n",
      "          28       0.50      0.59      0.54        22\n",
      "          29       0.95      0.90      0.92        20\n",
      "          31       0.53      0.56      0.55        16\n",
      "          32       0.71      0.65      0.68        23\n",
      "          33       0.65      0.55      0.59        20\n",
      "          34       0.58      0.73      0.65        15\n",
      "          35       0.74      0.74      0.74        19\n",
      "          36       0.56      0.64      0.60        14\n",
      "          37       0.69      0.67      0.68        33\n",
      "          38       0.50      0.45      0.48        11\n",
      "          39       0.50      0.59      0.54        17\n",
      "          41       0.14      0.40      0.21         5\n",
      "          42       0.67      0.47      0.55        30\n",
      "          43       0.12      0.07      0.09        15\n",
      "          44       0.68      0.63      0.65        27\n",
      "          45       0.92      0.85      0.88        13\n",
      "          46       0.50      0.25      0.33        16\n",
      "          48       0.71      0.60      0.65        20\n",
      "          49       0.75      0.38      0.50        16\n",
      "          50       0.70      0.92      0.79        25\n",
      "          51       0.47      0.39      0.42        18\n",
      "          52       0.58      0.54      0.56        28\n",
      "          53       0.50      0.50      0.50         2\n",
      "          54       0.45      0.71      0.56         7\n",
      "          55       0.63      0.76      0.69        62\n",
      "          56       0.50      0.35      0.41        17\n",
      "          57       0.82      0.64      0.72        28\n",
      "          58       0.50      0.60      0.55         5\n",
      "          59       0.77      0.73      0.75        55\n",
      "          60       0.39      0.60      0.47        47\n",
      "          61       0.86      0.86      0.86       100\n",
      "          62       0.88      0.92      0.90        25\n",
      "          63       0.50      0.69      0.58        13\n",
      "          64       0.79      0.52      0.63        21\n",
      "          65       0.89      0.94      0.91        17\n",
      "          66       0.43      0.43      0.43        28\n",
      "          67       0.58      0.72      0.65        29\n",
      "          68       0.17      0.50      0.25         4\n",
      "          69       1.00      0.83      0.91        12\n",
      "          70       1.00      0.75      0.86        12\n",
      "          71       0.51      0.39      0.44        46\n",
      "          72       0.44      0.22      0.30        18\n",
      "          73       0.86      0.73      0.79        44\n",
      "          74       0.94      0.88      0.91        17\n",
      "          78       0.60      0.35      0.44        17\n",
      "          79       0.91      0.77      0.83        13\n",
      "          80       0.85      0.70      0.77        33\n",
      "          81       0.50      0.33      0.40        12\n",
      "          82       0.87      0.65      0.74        20\n",
      "          83       0.61      0.69      0.65        16\n",
      "          85       0.58      0.50      0.54        36\n",
      "          86       0.82      0.82      0.82        34\n",
      "          87       0.53      0.56      0.54        18\n",
      "          88       0.55      0.72      0.63        29\n",
      "          89       0.00      0.00      0.00         1\n",
      "          90       0.98      0.99      0.99      2255\n",
      "\n",
      "    accuracy                           0.82      4067\n",
      "   macro avg       0.59      0.58      0.57      4067\n",
      "weighted avg       0.83      0.82      0.82      4067\n",
      "\n"
     ]
    }
   ],
   "source": [
    "report = classification_report(y_test, prediction)\n",
    "print(report)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "bfaaaf9c-2f56-449f-ba26-b031cc0a4837",
   "metadata": {},
   "source": [
    "#### (ii) SVM using Polynomial kernel"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "95997987-314a-4b9e-8de2-794d39e11b0e",
   "metadata": {},
   "outputs": [],
   "source": [
    "svc_model = SVC(kernel='poly', C=100, gamma = 0.05, coef0 = 0.005,degree = 3)\n",
    "svc_model.fit(X_train, y_train)\n",
    " \n",
    "prediction_poly = svc_model.predict(X_test)\n",
    "accuracy_poly = accuracy_score(prediction_poly,y_test)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "fa7c5443-f792-4684-90f6-57877764a379",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "              precision    recall  f1-score   support\n",
      "\n",
      "           0       0.38      0.83      0.53         6\n",
      "           1       0.56      0.75      0.64        12\n",
      "           2       0.85      0.97      0.91        35\n",
      "           3       1.00      0.78      0.88        18\n",
      "           4       0.25      0.15      0.19        13\n",
      "           5       0.82      0.82      0.82        11\n",
      "           6       0.42      0.76      0.54        34\n",
      "           7       0.43      0.55      0.48        11\n",
      "           8       0.54      0.50      0.52        42\n",
      "           9       0.66      0.64      0.65        45\n",
      "          11       0.85      0.58      0.69        38\n",
      "          12       0.47      0.46      0.47        39\n",
      "          13       0.39      0.50      0.44        14\n",
      "          15       0.31      0.36      0.33        11\n",
      "          16       0.38      0.65      0.48        20\n",
      "          17       0.65      0.55      0.59        20\n",
      "          18       0.00      0.00      0.00         7\n",
      "          19       0.50      0.82      0.62        11\n",
      "          20       0.57      0.59      0.58        22\n",
      "          21       0.42      0.41      0.42        39\n",
      "          22       0.83      0.50      0.62        20\n",
      "          23       0.50      0.40      0.44         5\n",
      "          24       0.75      0.95      0.84        19\n",
      "          25       0.38      0.50      0.43        24\n",
      "          26       0.27      0.31      0.29        13\n",
      "          27       0.21      0.14      0.17        22\n",
      "          28       0.50      0.50      0.50        22\n",
      "          29       0.94      0.80      0.86        20\n",
      "          31       0.78      0.44      0.56        16\n",
      "          32       0.58      0.65      0.61        23\n",
      "          33       0.75      0.60      0.67        20\n",
      "          34       0.65      0.73      0.69        15\n",
      "          35       0.78      0.74      0.76        19\n",
      "          36       0.53      0.64      0.58        14\n",
      "          37       0.69      0.73      0.71        33\n",
      "          38       0.64      0.64      0.64        11\n",
      "          39       0.52      0.65      0.58        17\n",
      "          41       0.07      0.20      0.10         5\n",
      "          42       0.65      0.57      0.61        30\n",
      "          43       0.43      0.20      0.27        15\n",
      "          44       0.59      0.63      0.61        27\n",
      "          45       0.92      0.85      0.88        13\n",
      "          46       0.56      0.31      0.40        16\n",
      "          48       0.85      0.55      0.67        20\n",
      "          49       0.69      0.56      0.62        16\n",
      "          50       0.68      0.92      0.78        25\n",
      "          51       0.89      0.44      0.59        18\n",
      "          52       0.48      0.50      0.49        28\n",
      "          53       0.50      1.00      0.67         2\n",
      "          54       0.42      0.71      0.53         7\n",
      "          55       0.72      0.77      0.74        62\n",
      "          56       0.46      0.35      0.40        17\n",
      "          57       0.77      0.61      0.68        28\n",
      "          58       0.00      0.00      0.00         5\n",
      "          59       0.90      0.64      0.74        55\n",
      "          60       0.41      0.53      0.46        47\n",
      "          61       0.86      0.88      0.87       100\n",
      "          62       0.89      1.00      0.94        25\n",
      "          63       0.48      0.77      0.59        13\n",
      "          64       0.88      0.67      0.76        21\n",
      "          65       0.94      0.94      0.94        17\n",
      "          66       0.50      0.43      0.46        28\n",
      "          67       0.56      0.69      0.62        29\n",
      "          68       0.20      0.25      0.22         4\n",
      "          69       1.00      0.75      0.86        12\n",
      "          70       0.82      0.75      0.78        12\n",
      "          71       0.65      0.48      0.55        46\n",
      "          72       0.64      0.39      0.48        18\n",
      "          73       0.77      0.61      0.68        44\n",
      "          74       0.84      0.94      0.89        17\n",
      "          78       0.75      0.53      0.62        17\n",
      "          79       1.00      0.85      0.92        13\n",
      "          80       0.74      0.70      0.72        33\n",
      "          81       0.58      0.58      0.58        12\n",
      "          82       0.67      0.60      0.63        20\n",
      "          83       0.57      0.75      0.65        16\n",
      "          85       0.59      0.56      0.57        36\n",
      "          86       0.82      0.68      0.74        34\n",
      "          87       0.56      0.50      0.53        18\n",
      "          88       0.56      0.76      0.65        29\n",
      "          89       0.50      1.00      0.67         1\n",
      "          90       0.99      0.99      0.99      2255\n",
      "\n",
      "    accuracy                           0.83      4067\n",
      "   macro avg       0.61      0.61      0.60      4067\n",
      "weighted avg       0.84      0.83      0.83      4067\n",
      "\n"
     ]
    }
   ],
   "source": [
    "report = classification_report(y_test, prediction_poly)\n",
    "print(report)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "5b7e9efb-9c85-48ca-8fa7-0de138349695",
   "metadata": {},
   "source": [
    "#### (iii) SVM using RBF kernel"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "c17963d5-826d-47cc-9a19-b5fafa047bc4",
   "metadata": {},
   "outputs": [],
   "source": [
    "svc_model = SVC(kernel='rbf', C=100000, gamma = 0.00055)\n",
    "svc_model.fit(X_train, y_train)\n",
    " \n",
    "prediction_rbf = svc_model.predict(X_test)\n",
    "accuracy_rbf = accuracy_score(prediction_rbf,y_test)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "1ad8dab0",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "              precision    recall  f1-score   support\n",
      "\n",
      "           0       0.38      0.83      0.53         6\n",
      "           1       0.50      0.83      0.62        12\n",
      "           2       0.80      0.94      0.87        35\n",
      "           3       0.93      0.78      0.85        18\n",
      "           4       0.29      0.31      0.30        13\n",
      "           5       0.89      0.73      0.80        11\n",
      "           6       0.48      0.74      0.58        34\n",
      "           7       0.33      0.18      0.24        11\n",
      "           8       0.47      0.52      0.49        42\n",
      "           9       0.65      0.71      0.68        45\n",
      "          11       0.72      0.74      0.73        38\n",
      "          12       0.38      0.38      0.38        39\n",
      "          13       0.46      0.43      0.44        14\n",
      "          15       0.27      0.36      0.31        11\n",
      "          16       0.45      0.65      0.53        20\n",
      "          17       0.83      0.50      0.62        20\n",
      "          18       0.00      0.00      0.00         7\n",
      "          19       0.70      0.64      0.67        11\n",
      "          20       0.62      0.68      0.65        22\n",
      "          21       0.38      0.41      0.40        39\n",
      "          22       1.00      0.65      0.79        20\n",
      "          23       0.25      0.20      0.22         5\n",
      "          24       0.82      0.95      0.88        19\n",
      "          25       0.35      0.38      0.36        24\n",
      "          26       0.31      0.31      0.31        13\n",
      "          27       0.27      0.14      0.18        22\n",
      "          28       0.41      0.41      0.41        22\n",
      "          29       0.89      0.85      0.87        20\n",
      "          31       0.70      0.44      0.54        16\n",
      "          32       0.55      0.70      0.62        23\n",
      "          33       0.79      0.75      0.77        20\n",
      "          34       0.69      0.73      0.71        15\n",
      "          35       0.70      0.74      0.72        19\n",
      "          36       0.53      0.64      0.58        14\n",
      "          37       0.74      0.76      0.75        33\n",
      "          38       0.64      0.64      0.64        11\n",
      "          39       0.63      0.71      0.67        17\n",
      "          41       0.12      0.40      0.19         5\n",
      "          42       0.63      0.63      0.63        30\n",
      "          43       1.00      0.20      0.33        15\n",
      "          44       0.68      0.63      0.65        27\n",
      "          45       0.93      1.00      0.96        13\n",
      "          46       0.50      0.12      0.20        16\n",
      "          48       0.78      0.70      0.74        20\n",
      "          49       0.77      0.62      0.69        16\n",
      "          50       0.96      0.88      0.92        25\n",
      "          51       0.57      0.44      0.50        18\n",
      "          52       0.52      0.61      0.56        28\n",
      "          53       0.00      0.00      0.00         2\n",
      "          54       0.50      0.71      0.59         7\n",
      "          55       0.70      0.81      0.75        62\n",
      "          56       0.67      0.35      0.46        17\n",
      "          57       0.85      0.61      0.71        28\n",
      "          58       0.40      0.40      0.40         5\n",
      "          59       0.91      0.53      0.67        55\n",
      "          60       0.44      0.55      0.49        47\n",
      "          61       0.86      0.89      0.88       100\n",
      "          62       0.86      1.00      0.93        25\n",
      "          63       0.45      0.77      0.57        13\n",
      "          64       0.88      0.67      0.76        21\n",
      "          65       0.94      0.94      0.94        17\n",
      "          66       0.50      0.39      0.44        28\n",
      "          67       0.59      0.69      0.63        29\n",
      "          68       0.22      0.50      0.31         4\n",
      "          69       1.00      0.67      0.80        12\n",
      "          70       0.90      0.75      0.82        12\n",
      "          71       0.60      0.39      0.47        46\n",
      "          72       0.59      0.56      0.57        18\n",
      "          73       0.77      0.68      0.72        44\n",
      "          74       0.93      0.76      0.84        17\n",
      "          78       0.82      0.53      0.64        17\n",
      "          79       0.91      0.77      0.83        13\n",
      "          80       0.81      0.79      0.80        33\n",
      "          81       0.43      0.50      0.46        12\n",
      "          82       0.71      0.60      0.65        20\n",
      "          83       0.59      0.62      0.61        16\n",
      "          85       0.59      0.44      0.51        36\n",
      "          86       0.90      0.76      0.83        34\n",
      "          87       0.40      0.56      0.47        18\n",
      "          88       0.52      0.83      0.64        29\n",
      "          89       0.00      0.00      0.00         1\n",
      "          90       0.99      1.00      1.00      2255\n",
      "\n",
      "    accuracy                           0.84      4067\n",
      "   macro avg       0.62      0.59      0.59      4067\n",
      "weighted avg       0.84      0.84      0.83      4067\n",
      "\n"
     ]
    }
   ],
   "source": [
    "report = classification_report(y_test, prediction_rbf)\n",
    "print(report)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.10 (default, Jun 22 2022, 20:18:18) \n[GCC 9.4.0]"
  },
  "vscode": {
   "interpreter": {
    "hash": "916dbcbb3f70747c44a77c7bcd40155683ae19c65e1c03b4aa3499c5328201f1"
   }
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
